package com.ruoyi.admin.controller;


import com.ruoyi.admin.domain.Question;
import com.ruoyi.admin.model.request.QuestionReq;
import com.ruoyi.admin.model.response.QuestionInfoResp;
import com.ruoyi.admin.service.QuestionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

/**
 * (Question)表控制层
 *
 * @author makejava
 * @since 2023-03-27 23:13:47
 */
@RestController
@RequestMapping("system/question")
public class QuestionController  extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private QuestionService questionService;

    /**
     * 分页查询所有数据
     * @param question 查询实体
     * @return 所有数据
     */
    @GetMapping("page")
    public TableDataInfo page(Question question) {
        List<QuestionInfoResp> questionPage = this.questionService.questionPage(buildPage(), question);
        return getDataTable(questionPage);
    }


    /**
     * 新增数据
     *
     * @param question 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody QuestionReq question) {
        return success(this.questionService.saveQuestion(question));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.questionService.getById(id));
    }



    /**
     * 修改数据
     *
     * @param question 实体对象
     * @return 修改结果
     */
    @PutMapping
    public AjaxResult update(@RequestBody Question question) {
        return success(this.questionService.updateById(question));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.questionService.removeByIds(idList));
    }
}

